package net.cathackers.devel.scmp.chat.interfaces;

import net.cathackers.devel.scmp.auth.interfaces.UserID;

public interface OnlineSessionsCache {
    /**
     * Add new session to the cache, this method uses optimistic approach, this means that it'll try to add the session
     * and it will trust the invoker that it has done the checks to make sure that no session conflicts happen
     * @param session
     */
    public void addSession(ChatSession session);
    /**
     * Removes the session from the cache 
     * @param session
     * 
     */
    public boolean removeSession(ChatSession session);
    /**
     * Removed session by ID
     * @param sessionID
     */
    public boolean removeSession(String sessionID);
    /**
     * check if there is already a session with a given session ID.
     * @param sessionID
     * @return true if sessionID exists
     */
    public boolean checkIfSessionIDExists(String sessionID);
    /**
     * checks if that UserID exists or not, if userID passed has resource set
     * then it'll check whether this resource exist in that user or not
     * if not then it'll check if this user has any resources available or not 
     * @param userID
     * @return true if userID exists
     */
    public boolean checkIfUserIDExists(UserID userID);
    /**
     * if you want to get a specific session using its sessionID, usually used before user authenticates.
     * @param sessionID
     * @return
     */
    public ChatSession getSessionBySessionID(String sessionID);
    /**
     * returns a list of applicable sessions for the UserID match.
     * if UserID has resource then you'll receive only one session 
     * if a user with this resource exist. if no resource was set in 
     * user id, then all sessions that are available for that user
     * will be returned.
     * @param userID
     * @return
     */
    public ChatSession[] getSession(UserID userID);
    /**
     * returns an array of references to all sessions that are online
     * on the server
     * @return
     */
    public ChatSession[] getAllSessions();
    /**
     * this is called when a user change his UserID information
     * this is usually done when a user is authenticated. 
     * @param sessionID
     */
    public void identifySession(String sessionID);
    /**
     * deletes everything and reset everything to default.
     */
    public void reset();
    /** 
     * returns the number of online users, including those who are not authenticated
     * @return
     */
    public int size();
    
    
}
